#! /bin/perl

# Extracts all javascript source files from an HTML file and combines it into
# a single large script file. Also handles conditional compilation target tags.

while(<>)
{
	if(/src\=\"([^\"]+.js)\"/)
	{
		my $fname = $1;
		print "\n\n\n\n\n// Start of File $fname\n\n\n\n\n\n";
		my $document = do {
			local $/ = undef;
			open INFILE, "<$fname"
				or die "could not open $fname: $!";
			<INFILE>;
		};
		close(INFILE);
		$document =~ s'\/\*\[targets\=html\]\*\/.*?\/\*\[\/targets\]\*\/''gm;
		print $document;
		print "\n";
	}
}
